package pakhib;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import pakhib.HibernateUtil;

public class ServiceEmploye {
	
	
	  SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
		Session session = null;
		

		public void add(Employe empl)
			{
			session =sessionFactory.openSession();
				//Session session = HibernateSessionFactory.getSession();
				Transaction tr = session.beginTransaction();
				session.save(empl);
				tr.commit();
			}
			
		/*	public List listEmploye()
			{
				//Session session = HibernateSessionFactory.getSession();
				session =sessionFactory.openSession();
				session.clear();
				Transaction tr = session.beginTransaction();
				Criteria cri = session.createCriteria(Employe.class);
				List res = cri.list();
				tr.commit();
				
				return res;
			}*/
	/*	public List listEmploye()
		{
			List l=new ArrayList<Employe>();
			Session session=HibernateUtil.getSessionFactory().openSession();
			 Transaction Tx=session.beginTransaction();
			// Employe employ=(Employe)session.load(Employe.class,new Integer(getListMatricule()));
			 String SQL_QUERY ="from Employe";
			 Query query = session.createQuery(SQL_QUERY);
			 System.out.println("ffffffffffffffffa");
			 List result = query.list();
			 
			
			//List list = session.find("from TContact where nom like '%t'");
			//Iterator it = result.iterator();
			/*while(it.hasNext())
			{
			  Employe employe = (Employe)it.next();
			//  System.out.println(contact.getNom());
			  
			  //Object[] row = (Object[]) it.next();
				
				l.add(it.next());
			}

			return result;
			 //String nomaffich=(String)row[1];
			
			//HibernateUtil.closeSession();
		
		}*/
	}



